<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Kubernetes集群监控之 Metrics Server | 十三不知</title><meta name="keywords" content="Kubernetes,监控"><meta name="author" content="张十三"><meta name="copyright" content="张十三"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="Kubernetes集群监控之 Metrics Server 监控指标 K8S资源指标获取工具：metrics-server ​		Kubernets早时候是使用的Heapster来实现完整的性能数据采集和监控功能，但是1.12后就废弃了，之后使用的替代者是metrics-server，从1.8版本开始，性能数据就开始以metrics-server API的方式提供标准化接口。metrics-se">
<meta property="og:type" content="article">
<meta property="og:title" content="Kubernetes集群监控之 Metrics Server">
<meta property="og:url" content="http://zuori.gitee.io/zaker/2021/03/30/Kubernetes%E9%9B%86%E7%BE%A4%E7%9B%91%E6%8E%A7%E4%B9%8B%20Metrics%20Server/index.html">
<meta property="og:site_name" content="十三不知">
<meta property="og:description" content="Kubernetes集群监控之 Metrics Server 监控指标 K8S资源指标获取工具：metrics-server ​		Kubernets早时候是使用的Heapster来实现完整的性能数据采集和监控功能，但是1.12后就废弃了，之后使用的替代者是metrics-server，从1.8版本开始，性能数据就开始以metrics-server API的方式提供标准化接口。metrics-se">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg">
<meta property="article:published_time" content="2021-03-30T06:46:36.000Z">
<meta property="article:modified_time" content="2021-03-30T07:19:12.824Z">
<meta property="article:author" content="张十三">
<meta property="article:tag" content="Kubernetes">
<meta property="article:tag" content="监控">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg"><link rel="shortcut icon" href="https://gitee.com/zuori/kaiscript/raw/master/images/20210325203813.png"><link rel="canonical" href="http://zuori.gitee.io/zaker/2021/03/30/Kubernetes%E9%9B%86%E7%BE%A4%E7%9B%91%E6%8E%A7%E4%B9%8B%20Metrics%20Server/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/zaker/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/zaker/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: 张十三","link":"链接: ","source":"来源: 十三不知","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-03-30 15:19:12'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    })(window)</script><meta name="generator" content="Hexo 5.4.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="https://gitee.com/zuori/kaiscript/raw/master/images/20210325192506.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/zaker/archives/"><div class="headline">文章</div><div class="length-num">13</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/zaker/tags/"><div class="headline">标签</div><div class="length-num">11</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/zaker/categories/"><div class="headline">分类</div><div class="length-num">4</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/zaker/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/zaker/archives/"><i class="fa-fw fas fa-archive"></i><span> Archives</span></a></div><div class="menus_item"><a class="site-page" href="/zaker/tags/"><i class="fa-fw fas fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/zaker/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/zaker/">十三不知</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/zaker/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/zaker/archives/"><i class="fa-fw fas fa-archive"></i><span> Archives</span></a></div><div class="menus_item"><a class="site-page" href="/zaker/tags/"><i class="fa-fw fas fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/zaker/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Kubernetes集群监控之 Metrics Server</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-03-30T06:46:36.000Z" title="发表于 2021-03-30 14:46:36">2021-03-30</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-03-30T07:19:12.824Z" title="更新于 2021-03-30 15:19:12">2021-03-30</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/zaker/categories/%E4%BA%91%E5%8E%9F%E7%94%9F/">云原生</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Kubernetes集群监控之 Metrics Server"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1>Kubernetes集群监控之 Metrics Server</h1>
<h2 id="监控指标">监控指标</h2>
<p>K8S资源指标获取工具：metrics-server</p>
<p>​		Kubernets早时候是使用的Heapster来实现完整的性能数据采集和监控功能，但是1.12后就废弃了，之后使用的替代者是metrics-server，从1.8版本开始，性能数据就开始以metrics-server API的方式提供标准化接口。metrics-server是由用户开发的一个api server，用于服务资源指标，而不是服务pod，deploy的。metrics-server本身不是k8s的组成部分，是托管运行在k8s上的一个pod。</p>
<p>​		在kubernetes的监控体系中，metrics-server用于提供核心的指标（Core Metrics），包括CPU累积使用率、内存的实时使用率、pod的资源占用率及容器的磁盘占用率。可以和kubelet以及由API server提供的api组成<strong>核心指标流水线</strong></p>
<p>​		当然有核心的就肯定还有非核心的，也就是所谓的自定义指标（Custom Metrics），有各种维度的资源指标，比如CPU利用率，网络连接的数量，网络报文的收发速率，包括进程的新建及回收速率等等，但是Kubernetes早期是不支持这些指标的监控的，所以就有了prometheus，可以把prometheus能采集到的各种指标整合进k8s里，能让K8S根据这些指标来判断是否需要根据这些指标来进行pod的伸缩。</p>
<p>​		prometheus既作为监控系统来使用，也作为某些特殊的资源指标的提供者来使用。但是这些指标不是标准的K8S内建指标，称之为自定义指标，但是prometheus要想将监控采集到的数据作为指标来展示，则需要一个插件，这个插件叫k8s-prometheus-adapter，这些指标判断pod是否需要伸缩的基本标准，例如根据cpu的利用率、内存使用量去进行伸缩。</p>
<h2 id="通过metrics-server监控pod、node、cpu指标">通过metrics-server监控pod、node、cpu指标</h2>
<h3 id="安装前检查">安装前检查</h3>
<p>这里我用docker-desktop初始化了一个单节点集群出来进行测试，k8s集群版本为1.19.7</p>
<p>先使用kubectl top node查看集群node资源状态</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">kubectl top node</span><br></pre></td></tr></table></figure>
<p><img src="https://gitee.com/zuori/kaiscript/raw/master/images/20210329000900.png" alt=""></p>
<p>可以看到这里现在是无法查询node的资源使用情况的，报错提示<code> Metrics API not available</code>，再执行命令查看api-server</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line"># kubectl get apiservice</span><br><span class="line">NAME                                   SERVICE   AVAILABLE   AGE</span><br><span class="line">v1.                                    Local     True        53d</span><br><span class="line">v1.admissionregistration.k8s.io        Local     True        53d</span><br><span class="line">v1.apiextensions.k8s.io                Local     True        53d</span><br><span class="line">v1.apps                                Local     True        53d</span><br><span class="line">v1.authentication.k8s.io               Local     True        53d</span><br><span class="line">v1.authorization.k8s.io                Local     True        53d</span><br><span class="line">v1.autoscaling                         Local     True        53d</span><br><span class="line">v1.batch                               Local     True        53d</span><br><span class="line">v1.catalog.cattle.io                   Local     True        11m</span><br><span class="line">v1.certificates.k8s.io                 Local     True        53d</span><br><span class="line">v1.coordination.k8s.io                 Local     True        53d</span><br><span class="line">v1.events.k8s.io                       Local     True        53d</span><br><span class="line">v1.monitoring.coreos.com               Local     True        11m</span><br><span class="line">v1.networking.k8s.io                   Local     True        53d</span><br><span class="line">v1.rancher.cattle.io                   Local     True        11m</span><br><span class="line">v1.rbac.authorization.k8s.io           Local     True        53d</span><br><span class="line">v1.scheduling.k8s.io                   Local     True        53d</span><br><span class="line">v1.storage.k8s.io                      Local     True        53d</span><br><span class="line">v1alpha1.fleet.cattle.io               Local     True        11m</span><br><span class="line">v1beta1.admissionregistration.k8s.io   Local     True        53d</span><br><span class="line">v1beta1.apiextensions.k8s.io           Local     True        53d</span><br><span class="line">v1beta1.authentication.k8s.io          Local     True        53d</span><br><span class="line">v1beta1.authorization.k8s.io           Local     True        53d</span><br><span class="line">v1beta1.batch                          Local     True        53d</span><br><span class="line">v1beta1.certificates.k8s.io            Local     True        53d</span><br><span class="line">v1beta1.coordination.k8s.io            Local     True        53d</span><br><span class="line">v1beta1.discovery.k8s.io               Local     True        53d</span><br><span class="line">v1beta1.events.k8s.io                  Local     True        53d</span><br><span class="line">v1beta1.extensions                     Local     True        53d</span><br><span class="line">v1beta1.networking.k8s.io              Local     True        53d</span><br><span class="line">v1beta1.node.k8s.io                    Local     True        53d</span><br><span class="line">v1beta1.policy                         Local     True        53d</span><br><span class="line">v1beta1.rbac.authorization.k8s.io      Local     True        53d</span><br><span class="line">v1beta1.scheduling.k8s.io              Local     True        53d</span><br><span class="line">v1beta1.storage.k8s.io                 Local     True        53d</span><br><span class="line">v2beta1.autoscaling                    Local     True        53d</span><br><span class="line">v2beta2.autoscaling                    Local     True        53d</span><br><span class="line">v3.management.cattle.io                Local     True        11m</span><br><span class="line">v3.project.cattle.io                   Local     True        11m</span><br></pre></td></tr></table></figure>
<p>或者执行kubectl api-versions</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"># kubectl api-versions</span><br><span class="line">admissionregistration.k8s.io&#x2F;v1</span><br><span class="line">admissionregistration.k8s.io&#x2F;v1beta1</span><br><span class="line">apiextensions.k8s.io&#x2F;v1</span><br><span class="line">apiextensions.k8s.io&#x2F;v1beta1</span><br><span class="line">apiregistration.k8s.io&#x2F;v1</span><br><span class="line">apiregistration.k8s.io&#x2F;v1beta1</span><br><span class="line">apps&#x2F;v1</span><br><span class="line">authentication.k8s.io&#x2F;v1</span><br><span class="line">authentication.k8s.io&#x2F;v1beta1</span><br><span class="line">authorization.k8s.io&#x2F;v1</span><br><span class="line">authorization.k8s.io&#x2F;v1beta1</span><br><span class="line">autoscaling&#x2F;v1</span><br><span class="line">autoscaling&#x2F;v2beta1</span><br><span class="line">autoscaling&#x2F;v2beta2</span><br><span class="line">batch&#x2F;v1</span><br><span class="line">batch&#x2F;v1beta1</span><br><span class="line">catalog.cattle.io&#x2F;v1</span><br><span class="line">certificates.k8s.io&#x2F;v1</span><br><span class="line">certificates.k8s.io&#x2F;v1beta1</span><br><span class="line">coordination.k8s.io&#x2F;v1</span><br><span class="line">coordination.k8s.io&#x2F;v1beta1</span><br><span class="line">discovery.k8s.io&#x2F;v1beta1</span><br><span class="line">events.k8s.io&#x2F;v1</span><br><span class="line">events.k8s.io&#x2F;v1beta1</span><br><span class="line">extensions&#x2F;v1beta1</span><br><span class="line">fleet.cattle.io&#x2F;v1alpha1</span><br><span class="line">management.cattle.io&#x2F;v3</span><br><span class="line">monitoring.coreos.com&#x2F;v1</span><br><span class="line">networking.k8s.io&#x2F;v1</span><br><span class="line">networking.k8s.io&#x2F;v1beta1</span><br><span class="line">node.k8s.io&#x2F;v1beta1</span><br><span class="line">policy&#x2F;v1beta1</span><br><span class="line">project.cattle.io&#x2F;v3</span><br><span class="line">rancher.cattle.io&#x2F;v1</span><br><span class="line">rbac.authorization.k8s.io&#x2F;v1</span><br><span class="line">rbac.authorization.k8s.io&#x2F;v1beta1</span><br><span class="line">scheduling.k8s.io&#x2F;v1</span><br><span class="line">scheduling.k8s.io&#x2F;v1beta1</span><br><span class="line">storage.k8s.io&#x2F;v1</span><br><span class="line">storage.k8s.io&#x2F;v1beta1</span><br><span class="line">v1</span><br></pre></td></tr></table></figure>
<p>可以看到是都是没有metrics.k8s.io这个组的的，所以需要安装metrics-server。</p>
<h3 id="部署Metrics-server">部署Metrics-server</h3>
<p>部署文件获取地址：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">https:&#x2F;&#x2F;github.com&#x2F;kubernetes-sigs&#x2F;metrics-server</span><br></pre></td></tr></table></figure>
<p>可以看到最新版的release</p>
<p><img src="https://gitee.com/zuori/kaiscript/raw/master/images/20210329002742.png" alt=""></p>
<p>需要执行就可以部署</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">kubectl apply -f https:&#x2F;&#x2F;github.com&#x2F;kubernetes-sigs&#x2F;metrics-server&#x2F;releases&#x2F;download&#x2F;v0.4.2&#x2F;components.yaml</span><br></pre></td></tr></table></figure>
<p>为了方便的看到里面的内容，这里先把文件直接拉到本地</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -O https:&#x2F;&#x2F;github.com&#x2F;kubernetes-sigs&#x2F;metrics-server&#x2F;releases&#x2F;download&#x2F;v0.4.2&#x2F;components.yaml</span><br></pre></td></tr></table></figure>
<p>查看其中的内容：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br></pre></td><td class="code"><pre><span class="line">apiVersion: v1</span><br><span class="line">kind: ServiceAccount</span><br><span class="line">metadata:</span><br><span class="line">  labels:</span><br><span class="line">    k8s-app: metrics-server</span><br><span class="line">  name: metrics-server</span><br><span class="line">  namespace: kube-system</span><br><span class="line">---</span><br><span class="line">apiVersion: rbac.authorization.k8s.io&#x2F;v1</span><br><span class="line">kind: ClusterRole</span><br><span class="line">metadata:</span><br><span class="line">  labels:</span><br><span class="line">    k8s-app: metrics-server</span><br><span class="line">    rbac.authorization.k8s.io&#x2F;aggregate-to-admin: &quot;true&quot;</span><br><span class="line">    rbac.authorization.k8s.io&#x2F;aggregate-to-edit: &quot;true&quot;</span><br><span class="line">    rbac.authorization.k8s.io&#x2F;aggregate-to-view: &quot;true&quot;</span><br><span class="line">  name: system:aggregated-metrics-reader</span><br><span class="line">rules:</span><br><span class="line">- apiGroups:</span><br><span class="line">  - metrics.k8s.io</span><br><span class="line">  resources:</span><br><span class="line">  - pods</span><br><span class="line">  - nodes</span><br><span class="line">  verbs:</span><br><span class="line">  - get</span><br><span class="line">  - list</span><br><span class="line">  - watch</span><br><span class="line">---</span><br><span class="line">apiVersion: rbac.authorization.k8s.io&#x2F;v1</span><br><span class="line">kind: ClusterRole</span><br><span class="line">metadata:</span><br><span class="line">  labels:</span><br><span class="line">    k8s-app: metrics-server</span><br><span class="line">  name: system:metrics-server</span><br><span class="line">rules:</span><br><span class="line">- apiGroups:</span><br><span class="line">  - &quot;&quot;</span><br><span class="line">  resources:</span><br><span class="line">  - pods</span><br><span class="line">  - nodes</span><br><span class="line">  - nodes&#x2F;stats</span><br><span class="line">  - namespaces</span><br><span class="line">  - configmaps</span><br><span class="line">  verbs:</span><br><span class="line">  - get</span><br><span class="line">  - list</span><br><span class="line">  - watch</span><br><span class="line">---</span><br><span class="line">apiVersion: rbac.authorization.k8s.io&#x2F;v1</span><br><span class="line">kind: RoleBinding</span><br><span class="line">metadata:</span><br><span class="line">  labels:</span><br><span class="line">    k8s-app: metrics-server</span><br><span class="line">  name: metrics-server-auth-reader</span><br><span class="line">  namespace: kube-system</span><br><span class="line">roleRef:</span><br><span class="line">  apiGroup: rbac.authorization.k8s.io</span><br><span class="line">  kind: Role</span><br><span class="line">  name: extension-apiserver-authentication-reader</span><br><span class="line">subjects:</span><br><span class="line">- kind: ServiceAccount</span><br><span class="line">  name: metrics-server</span><br><span class="line">  namespace: kube-system</span><br><span class="line">---</span><br><span class="line">apiVersion: rbac.authorization.k8s.io&#x2F;v1</span><br><span class="line">kind: ClusterRoleBinding</span><br><span class="line">metadata:</span><br><span class="line">  labels:</span><br><span class="line">    k8s-app: metrics-server</span><br><span class="line">  name: metrics-server:system:auth-delegator</span><br><span class="line">roleRef:</span><br><span class="line">  apiGroup: rbac.authorization.k8s.io</span><br><span class="line">  kind: ClusterRole</span><br><span class="line">  name: system:auth-delegator</span><br><span class="line">subjects:</span><br><span class="line">- kind: ServiceAccount</span><br><span class="line">  name: metrics-server</span><br><span class="line">  namespace: kube-system</span><br><span class="line">---</span><br><span class="line">apiVersion: rbac.authorization.k8s.io&#x2F;v1</span><br><span class="line">kind: ClusterRoleBinding</span><br><span class="line">metadata:</span><br><span class="line">  labels:</span><br><span class="line">    k8s-app: metrics-server</span><br><span class="line">  name: system:metrics-server</span><br><span class="line">roleRef:</span><br><span class="line">  apiGroup: rbac.authorization.k8s.io</span><br><span class="line">  kind: ClusterRole</span><br><span class="line">  name: system:metrics-server</span><br><span class="line">subjects:</span><br><span class="line">- kind: ServiceAccount</span><br><span class="line">  name: metrics-server</span><br><span class="line">  namespace: kube-system</span><br><span class="line">---</span><br><span class="line">apiVersion: v1</span><br><span class="line">kind: Service</span><br><span class="line">metadata:</span><br><span class="line">  labels:</span><br><span class="line">    k8s-app: metrics-server</span><br><span class="line">  name: metrics-server</span><br><span class="line">  namespace: kube-system</span><br><span class="line">spec:</span><br><span class="line">  ports:</span><br><span class="line">  - name: https</span><br><span class="line">    port: 443</span><br><span class="line">    protocol: TCP</span><br><span class="line">    targetPort: https</span><br><span class="line">  selector:</span><br><span class="line">    k8s-app: metrics-server</span><br><span class="line">---</span><br><span class="line">apiVersion: apps&#x2F;v1</span><br><span class="line">kind: Deployment</span><br><span class="line">metadata:</span><br><span class="line">  labels:</span><br><span class="line">    k8s-app: metrics-server</span><br><span class="line">  name: metrics-server</span><br><span class="line">  namespace: kube-system</span><br><span class="line">spec:</span><br><span class="line">  selector:</span><br><span class="line">    matchLabels:</span><br><span class="line">      k8s-app: metrics-server</span><br><span class="line">  strategy:</span><br><span class="line">    rollingUpdate:</span><br><span class="line">      maxUnavailable: 0</span><br><span class="line">  template:</span><br><span class="line">    metadata:</span><br><span class="line">      labels:</span><br><span class="line">        k8s-app: metrics-server</span><br><span class="line">    spec:</span><br><span class="line">      containers:</span><br><span class="line">      - args:</span><br><span class="line">        - --cert-dir&#x3D;&#x2F;tmp</span><br><span class="line">        - --secure-port&#x3D;4443</span><br><span class="line">        - --kubelet-preferred-address-types&#x3D;InternalIP,ExternalIP,Hostname</span><br><span class="line">        - --kubelet-use-node-status-port</span><br><span class="line">        image: k8s.gcr.io&#x2F;metrics-server&#x2F;metrics-server:v0.4.2</span><br><span class="line">        imagePullPolicy: IfNotPresent</span><br><span class="line">        livenessProbe:</span><br><span class="line">          failureThreshold: 3</span><br><span class="line">          httpGet:</span><br><span class="line">            path: &#x2F;livez</span><br><span class="line">            port: https</span><br><span class="line">            scheme: HTTPS</span><br><span class="line">          periodSeconds: 10</span><br><span class="line">        name: metrics-server</span><br><span class="line">        ports:</span><br><span class="line">        - containerPort: 4443</span><br><span class="line">          name: https</span><br><span class="line">          protocol: TCP</span><br><span class="line">        readinessProbe:</span><br><span class="line">          failureThreshold: 3</span><br><span class="line">          httpGet:</span><br><span class="line">            path: &#x2F;readyz</span><br><span class="line">            port: https</span><br><span class="line">            scheme: HTTPS</span><br><span class="line">          periodSeconds: 10</span><br><span class="line">        securityContext:</span><br><span class="line">          readOnlyRootFilesystem: true</span><br><span class="line">          runAsNonRoot: true</span><br><span class="line">          runAsUser: 1000</span><br><span class="line">        volumeMounts:</span><br><span class="line">        - mountPath: &#x2F;tmp</span><br><span class="line">          name: tmp-dir</span><br><span class="line">      nodeSelector:</span><br><span class="line">        kubernetes.io&#x2F;os: linux</span><br><span class="line">      priorityClassName: system-cluster-critical</span><br><span class="line">      serviceAccountName: metrics-server</span><br><span class="line">      volumes:</span><br><span class="line">      - emptyDir: &#123;&#125;</span><br><span class="line">        name: tmp-dir</span><br><span class="line">---</span><br><span class="line">apiVersion: apiregistration.k8s.io&#x2F;v1</span><br><span class="line">kind: APIService</span><br><span class="line">metadata:</span><br><span class="line">  labels:</span><br><span class="line">    k8s-app: metrics-server</span><br><span class="line">  name: v1beta1.metrics.k8s.io</span><br><span class="line">spec:</span><br><span class="line">  group: metrics.k8s.io</span><br><span class="line">  groupPriorityMinimum: 100</span><br><span class="line">  insecureSkipTLSVerify: true</span><br><span class="line">  service:</span><br><span class="line">    name: metrics-server</span><br><span class="line">    namespace: kube-system</span><br><span class="line">  version: v1beta1</span><br><span class="line">  versionPriority: 100</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>其中文件可以看出其中包含的组件有：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">ServiceAccount&#x2F;metrics-server</span><br><span class="line">ClusterRole&#x2F;system:aggregated-metrics-reader</span><br><span class="line">ClusterRole&#x2F;system:metrics-server</span><br><span class="line">RoleBinding&#x2F;extension-apiserver-authentication-reader</span><br><span class="line">ClusterRoleBinding&#x2F;metrics-server:system:auth-delegator</span><br><span class="line">ClusterRoleBinding&#x2F;system:metrics-server</span><br><span class="line">deployment.apps&#x2F;metrics-server</span><br><span class="line">service&#x2F;metrics-server</span><br><span class="line">replicaset.apps&#x2F;metrics-server-76f8d9fc69</span><br><span class="line">APIService&#x2F;metrics-server</span><br></pre></td></tr></table></figure>
<p>然后进行部署：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">kubectl apply -f components.yaml</span><br></pre></td></tr></table></figure>
<p><img src="https://gitee.com/zuori/kaiscript/raw/master/images/20210329004326.png" alt=""></p>
<p>查看kube-system这个ns下的资源</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"># kubectl -n kube-system get all</span><br><span class="line">NAME                                         READY   STATUS    RESTARTS   AGE</span><br><span class="line">pod&#x2F;coredns-f9fd979d6-rwxwr                  1&#x2F;1     Running   6          53d</span><br><span class="line">pod&#x2F;coredns-f9fd979d6-sx6jt                  1&#x2F;1     Running   6          53d</span><br><span class="line">pod&#x2F;etcd-docker-desktop                      1&#x2F;1     Running   7          53d</span><br><span class="line">pod&#x2F;kube-apiserver-docker-desktop            1&#x2F;1     Running   9          53d</span><br><span class="line">pod&#x2F;kube-controller-manager-docker-desktop   1&#x2F;1     Running   6          53d</span><br><span class="line">pod&#x2F;kube-proxy-xr4g8                         1&#x2F;1     Running   6          53d</span><br><span class="line">pod&#x2F;kube-scheduler-docker-desktop            1&#x2F;1     Running   44         53d</span><br><span class="line">pod&#x2F;metrics-server-76f8d9fc69-5g9hq          0&#x2F;1     Running   10         20m</span><br><span class="line">pod&#x2F;storage-provisioner                      1&#x2F;1     Running   44         53d</span><br><span class="line">pod&#x2F;vpnkit-controller                        1&#x2F;1     Running   6          53d</span><br><span class="line"></span><br><span class="line">NAME                     TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                  AGE</span><br><span class="line">service&#x2F;kube-dns         ClusterIP   10.96.0.10      &lt;none&gt;        53&#x2F;UDP,53&#x2F;TCP,9153&#x2F;TCP   53d</span><br><span class="line">service&#x2F;metrics-server   ClusterIP   10.109.12.249   &lt;none&gt;        443&#x2F;TCP                  20m</span><br><span class="line"></span><br><span class="line">NAME                        DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE</span><br><span class="line">daemonset.apps&#x2F;kube-proxy   1         1         1       1            1           kubernetes.io&#x2F;os&#x3D;linux   53d</span><br><span class="line"></span><br><span class="line">NAME                             READY   UP-TO-DATE   AVAILABLE   AGE</span><br><span class="line">deployment.apps&#x2F;coredns          2&#x2F;2     2            2           53d</span><br><span class="line">deployment.apps&#x2F;metrics-server   0&#x2F;1     1            0           20m</span><br><span class="line"></span><br><span class="line">NAME                                        DESIRED   CURRENT   READY   AGE</span><br><span class="line">replicaset.apps&#x2F;coredns-f9fd979d6           2         2         2       53d</span><br><span class="line">replicaset.apps&#x2F;metrics-server-76f8d9fc69   1         1         0       20m</span><br></pre></td></tr></table></figure>
<p>发现报错，打印日志查看报错信息：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">#kubectl -n kube-system  logs -f metrics-server-76f8d9fc69-5g9hq</span><br><span class="line">E0328 17:03:34.901101       1 server.go:132] unable to fully scrape metrics: unable to fully scrape metrics from node docker-desktop: unable to fetch metrics from node docker-desktop: Get &quot;https:&#x2F;&#x2F;192.168.65.4:10250&#x2F;stats&#x2F;summary?only_cpu_and_memory&#x3D;true&quot;: x509: cannot validate certificate for 192.168.65.4 because it doesn&#39;t contain any IP SANs</span><br><span class="line">I0328 17:03:34.967742       1 configmap_cafile_content.go:202] Starting client-ca::kube-system::extension-apiserver-authentication::requestheader-client-ca-file</span><br><span class="line">I0328 17:03:34.968014       1 dynamic_serving_content.go:130] Starting serving-cert::&#x2F;tmp&#x2F;apiserver.crt::&#x2F;tmp&#x2F;apiserver.key</span><br><span class="line">I0328 17:03:34.968084       1 shared_informer.go:240] Waiting for caches to sync for client-ca::kube-system::extension-apiserver-authentication::requestheader-client-ca-file</span><br><span class="line">I0328 17:03:34.968005       1 configmap_cafile_content.go:202] Starting client-ca::kube-system::extension-apiserver-authentication::client-ca-file</span><br><span class="line">I0328 17:03:34.968671       1 requestheader_controller.go:169] Starting RequestHeaderAuthRequestController</span><br><span class="line">I0328 17:03:34.969475       1 shared_informer.go:240] Waiting for caches to sync for RequestHeaderAuthRequestController</span><br><span class="line">I0328 17:03:34.969142       1 tlsconfig.go:240] Starting DynamicServingCertificateController</span><br><span class="line">I0328 17:03:34.969449       1 shared_informer.go:240] Waiting for caches to sync for client-ca::kube-system::extension-apiserver-authentication::client-ca-file</span><br><span class="line">I0328 17:03:34.970339       1 secure_serving.go:197] Serving securely on [::]:4443</span><br><span class="line">I0328 17:03:35.070604       1 shared_informer.go:247] Caches are synced for client-ca::kube-system::extension-apiserver-authentication::client-ca-file</span><br><span class="line">I0328 17:03:35.070600       1 shared_informer.go:247] Caches are synced for client-ca::kube-system::extension-apiserver-authentication::requestheader-client-ca-file</span><br><span class="line">I0328 17:03:35.070649       1 shared_informer.go:247] Caches are synced for RequestHeaderAuthRequestController</span><br><span class="line">I0328 17:04:03.464357       1 dynamic_serving_content.go:145] Shutting down serving-cert::&#x2F;tmp&#x2F;apiserver.crt::&#x2F;tmp&#x2F;apiserver.key</span><br><span class="line">I0328 17:04:03.464561       1 configmap_cafile_content.go:223] Shutting down client-ca::kube-system::extension-apiserver-authentication::client-ca-file</span><br><span class="line">I0328 17:04:03.465869       1 requestheader_controller.go:183] Shutting down RequestHeaderAuthRequestController</span><br><span class="line">I0328 17:04:03.464485       1 tlsconfig.go:255] Shutting down DynamicServingCertificateController</span><br><span class="line">I0328 17:04:03.467618       1 configmap_cafile_content.go:223] Shutting down client-ca::kube-system::extension-apiserver-authentication::requestheader-client-ca-file</span><br></pre></td></tr></table></figure>
<p>看日志报错好像是客户端的证书验证不通过,所以需要跳过ca验证</p>
<p>添加–kubelet-insecure-tls，表示不验证客户端的证书</p>
<p><img src="https://gitee.com/zuori/kaiscript/raw/master/images/20210329234720.png" alt=""></p>
<p>然后重新部署kubectl apply -f components.yaml，再查看资源信息</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">#kubectl -n kube-system  get all</span><br><span class="line"></span><br><span class="line">NAME                                         READY   STATUS    RESTARTS   AGE</span><br><span class="line">pod&#x2F;coredns-f9fd979d6-rwxwr                  1&#x2F;1     Running   8          54d</span><br><span class="line">pod&#x2F;coredns-f9fd979d6-sx6jt                  1&#x2F;1     Running   8          54d</span><br><span class="line">pod&#x2F;etcd-docker-desktop                      1&#x2F;1     Running   9          54d</span><br><span class="line">pod&#x2F;kube-apiserver-docker-desktop            1&#x2F;1     Running   11         54d</span><br><span class="line">pod&#x2F;kube-controller-manager-docker-desktop   1&#x2F;1     Running   8          54d</span><br><span class="line">pod&#x2F;kube-proxy-xr4g8                         1&#x2F;1     Running   8          54d</span><br><span class="line">pod&#x2F;kube-scheduler-docker-desktop            1&#x2F;1     Running   47         54d</span><br><span class="line">pod&#x2F;metrics-server-5b78d5f9c6-nz6r2          1&#x2F;1     Running   0          15s</span><br><span class="line">pod&#x2F;storage-provisioner                      1&#x2F;1     Running   47         54d</span><br><span class="line">pod&#x2F;vpnkit-controller                        1&#x2F;1     Running   8          54d</span><br><span class="line"></span><br><span class="line">NAME                     TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                  AGE</span><br><span class="line">service&#x2F;kube-dns         ClusterIP   10.96.0.10      &lt;none&gt;        53&#x2F;UDP,53&#x2F;TCP,9153&#x2F;TCP   54d</span><br><span class="line">service&#x2F;metrics-server   ClusterIP   10.109.12.249   &lt;none&gt;        443&#x2F;TCP                  23h</span><br><span class="line"></span><br><span class="line">NAME                        DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE</span><br><span class="line">daemonset.apps&#x2F;kube-proxy   1         1         1       1            1           kubernetes.io&#x2F;os&#x3D;linux   54d</span><br><span class="line"></span><br><span class="line">NAME                             READY   UP-TO-DATE   AVAILABLE   AGE</span><br><span class="line">deployment.apps&#x2F;coredns          2&#x2F;2     2            2           54d</span><br><span class="line">deployment.apps&#x2F;metrics-server   1&#x2F;1     1            1           23h</span><br><span class="line"></span><br><span class="line">NAME                                        DESIRED   CURRENT   READY   AGE</span><br><span class="line">replicaset.apps&#x2F;coredns-f9fd979d6           2         2         2       54d</span><br><span class="line">replicaset.apps&#x2F;metrics-server-5b78d5f9c6   1         1         1       15s</span><br><span class="line">replicaset.apps&#x2F;metrics-server-76f8d9fc69   0         0         0       23h</span><br></pre></td></tr></table></figure>
<p>表示已经全部执行成功。</p>
<h3 id="部署后测试">部署后测试</h3>
<p>这个时候测试集群监控，执行<code>kubectl top node</code>,返回结果为正确值，表示部署成功。</p>
<p><img src="https://gitee.com/zuori/kaiscript/raw/master/images/20210329235218.png" alt=""></p>
<p>还可以测试监控pod的数据，结果返回正常。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"># kubectl -n kube-system  top pod</span><br><span class="line">NAME                                     CPU(cores)   MEMORY(bytes)</span><br><span class="line">coredns-f9fd979d6-rwxwr                  5m           10Mi</span><br><span class="line">coredns-f9fd979d6-sx6jt                  4m           12Mi</span><br><span class="line">etcd-docker-desktop                      53m          56Mi</span><br><span class="line">kube-apiserver-docker-desktop            131m         533Mi</span><br><span class="line">kube-controller-manager-docker-desktop   24m          66Mi</span><br><span class="line">kube-proxy-xr4g8                         1m           13Mi</span><br><span class="line">kube-scheduler-docker-desktop            5m           22Mi</span><br><span class="line">metrics-server-5b78d5f9c6-nz6r2          3m           20Mi</span><br><span class="line">storage-provisioner                      2m           8Mi</span><br><span class="line">vpnkit-controller                        0m           7Mi</span><br></pre></td></tr></table></figure>
<p>查看kubectl  api-versions</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line">kubectl api-versions</span><br><span class="line">admissionregistration.k8s.io&#x2F;v1</span><br><span class="line">admissionregistration.k8s.io&#x2F;v1beta1</span><br><span class="line">apiextensions.k8s.io&#x2F;v1</span><br><span class="line">apiextensions.k8s.io&#x2F;v1beta1</span><br><span class="line">apiregistration.k8s.io&#x2F;v1</span><br><span class="line">apiregistration.k8s.io&#x2F;v1beta1</span><br><span class="line">apps&#x2F;v1</span><br><span class="line">authentication.k8s.io&#x2F;v1</span><br><span class="line">authentication.k8s.io&#x2F;v1beta1</span><br><span class="line">authorization.k8s.io&#x2F;v1</span><br><span class="line">authorization.k8s.io&#x2F;v1beta1</span><br><span class="line">autoscaling&#x2F;v1</span><br><span class="line">autoscaling&#x2F;v2beta1</span><br><span class="line">autoscaling&#x2F;v2beta2</span><br><span class="line">batch&#x2F;v1</span><br><span class="line">batch&#x2F;v1beta1</span><br><span class="line">catalog.cattle.io&#x2F;v1</span><br><span class="line">certificates.k8s.io&#x2F;v1</span><br><span class="line">certificates.k8s.io&#x2F;v1beta1</span><br><span class="line">coordination.k8s.io&#x2F;v1</span><br><span class="line">coordination.k8s.io&#x2F;v1beta1</span><br><span class="line">discovery.k8s.io&#x2F;v1beta1</span><br><span class="line">events.k8s.io&#x2F;v1</span><br><span class="line">events.k8s.io&#x2F;v1beta1</span><br><span class="line">extensions&#x2F;v1beta1</span><br><span class="line">fleet.cattle.io&#x2F;v1alpha1</span><br><span class="line">management.cattle.io&#x2F;v3</span><br><span class="line">metrics.k8s.io&#x2F;v1beta1</span><br><span class="line">monitoring.coreos.com&#x2F;v1</span><br><span class="line">networking.k8s.io&#x2F;v1</span><br><span class="line">networking.k8s.io&#x2F;v1beta1</span><br><span class="line">node.k8s.io&#x2F;v1beta1</span><br><span class="line">policy&#x2F;v1beta1</span><br><span class="line">project.cattle.io&#x2F;v3</span><br><span class="line">rancher.cattle.io&#x2F;v1</span><br><span class="line">rbac.authorization.k8s.io&#x2F;v1</span><br><span class="line">rbac.authorization.k8s.io&#x2F;v1beta1</span><br><span class="line">scheduling.k8s.io&#x2F;v1</span><br><span class="line">scheduling.k8s.io&#x2F;v1beta1</span><br><span class="line">storage.k8s.io&#x2F;v1</span><br><span class="line">storage.k8s.io&#x2F;v1beta1</span><br><span class="line">v1</span><br></pre></td></tr></table></figure>
<p><a target="_blank" rel="noopener" href="http://xn--metrics-rp4kr1a44vp6ev5t1un7t9fcmyasice33j.k8s.io/v1beta1,%E9%83%A8%E7%BD%B2%E6%88%90%E5%8A%9F%EF%BC%81">可以看到已经部署好了metrics.k8s.io/v1beta1,部署成功！</a></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">张十三</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://zuori.gitee.io/zaker/2021/03/30/Kubernetes%E9%9B%86%E7%BE%A4%E7%9B%91%E6%8E%A7%E4%B9%8B%20Metrics%20Server/">http://zuori.gitee.io/zaker/2021/03/30/Kubernetes%E9%9B%86%E7%BE%A4%E7%9B%91%E6%8E%A7%E4%B9%8B%20Metrics%20Server/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://zuori.gitee.io/zaker" target="_blank">十三不知</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/zaker/tags/Kubernetes/">Kubernetes</a><a class="post-meta__tags" href="/zaker/tags/%E7%9B%91%E6%8E%A7/">监控</a></div><div class="post_share"><div class="addthis_inline_share_toolbox"></div><script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=null" async="async"></script></div></div><nav class="pagination-post" id="pagination"><div class="next-post pull-full"><a href="/zaker/2021/03/26/RabbitMq%E5%9F%BA%E7%A1%80%E4%BD%BF%E7%94%A8/"><img class="next-cover" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="onerror=null;src='/zaker/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">RabbitMq学习笔记</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/zaker/2021/03/25/K8s可视化监控之-Weave Scope/" title="Kubernetes集群可视化监控之-Weave Scope"><img class="cover" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-03-25</div><div class="title">Kubernetes集群可视化监控之-Weave Scope</div></div></a></div><div><a href="/zaker/2021/02/25/Rancher的高可用安装/" title="Rancher的高可用部署"><img class="cover" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-02-25</div><div class="title">Rancher的高可用部署</div></div></a></div><div><a href="/zaker/2019/04/25/YAML语法/" title="YAML语法简介"><img class="cover" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-04-25</div><div class="title">YAML语法简介</div></div></a></div><div><a href="/zaker/2021/02/25/配置StorageClass/" title="创建StorageClass"><img class="cover" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-02-25</div><div class="title">创建StorageClass</div></div></a></div><div><a href="/zaker/2021/03/03/Kubectl基本使用/" title="kubectl 基本使用"><img class="cover" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-03-03</div><div class="title">kubectl 基本使用</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" src="https://gitee.com/zuori/kaiscript/raw/master/images/20210325192506.jpg" onerror="this.onerror=null;this.src='/zaker/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">张十三</div><div class="author-info__description"></div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/zaker/archives/"><div class="headline">文章</div><div class="length-num">13</div></a></div><div class="card-info-data-item is-center"><a href="/zaker/tags/"><div class="headline">标签</div><div class="length-num">11</div></a></div><div class="card-info-data-item is-center"><a href="/zaker/categories/"><div class="headline">分类</div><div class="length-num">4</div></a></div></div><a class="button--animated" id="card-info-btn" href="http://zuori.gitee.io/zaker"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">记录一点东西的地方</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">1.</span> <span class="toc-text">Kubernetes集群监控之 Metrics Server</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%9B%91%E6%8E%A7%E6%8C%87%E6%A0%87"><span class="toc-number">1.1.</span> <span class="toc-text">监控指标</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%80%9A%E8%BF%87metrics-server%E7%9B%91%E6%8E%A7pod%E3%80%81node%E3%80%81cpu%E6%8C%87%E6%A0%87"><span class="toc-number">1.2.</span> <span class="toc-text">通过metrics-server监控pod、node、cpu指标</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%89%E8%A3%85%E5%89%8D%E6%A3%80%E6%9F%A5"><span class="toc-number">1.2.1.</span> <span class="toc-text">安装前检查</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%83%A8%E7%BD%B2Metrics-server"><span class="toc-number">1.2.2.</span> <span class="toc-text">部署Metrics-server</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%83%A8%E7%BD%B2%E5%90%8E%E6%B5%8B%E8%AF%95"><span class="toc-number">1.2.3.</span> <span class="toc-text">部署后测试</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/zaker/2021/03/30/Kubernetes%E9%9B%86%E7%BE%A4%E7%9B%91%E6%8E%A7%E4%B9%8B%20Metrics%20Server/" title="Kubernetes集群监控之 Metrics Server"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/zaker/img/404.jpg'" alt="Kubernetes集群监控之 Metrics Server"/></a><div class="content"><a class="title" href="/zaker/2021/03/30/Kubernetes%E9%9B%86%E7%BE%A4%E7%9B%91%E6%8E%A7%E4%B9%8B%20Metrics%20Server/" title="Kubernetes集群监控之 Metrics Server">Kubernetes集群监控之 Metrics Server</a><time datetime="2021-03-30T06:46:36.000Z" title="发表于 2021-03-30 14:46:36">2021-03-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/zaker/2021/03/26/RabbitMq%E5%9F%BA%E7%A1%80%E4%BD%BF%E7%94%A8/" title="RabbitMq学习笔记"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/zaker/img/404.jpg'" alt="RabbitMq学习笔记"/></a><div class="content"><a class="title" href="/zaker/2021/03/26/RabbitMq%E5%9F%BA%E7%A1%80%E4%BD%BF%E7%94%A8/" title="RabbitMq学习笔记">RabbitMq学习笔记</a><time datetime="2021-03-26T01:46:36.000Z" title="发表于 2021-03-26 09:46:36">2021-03-26</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/zaker/2021/03/25/K8s%E5%8F%AF%E8%A7%86%E5%8C%96%E7%9B%91%E6%8E%A7%E4%B9%8B-Weave%20Scope/" title="Kubernetes集群可视化监控之-Weave Scope"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/zaker/img/404.jpg'" alt="Kubernetes集群可视化监控之-Weave Scope"/></a><div class="content"><a class="title" href="/zaker/2021/03/25/K8s%E5%8F%AF%E8%A7%86%E5%8C%96%E7%9B%91%E6%8E%A7%E4%B9%8B-Weave%20Scope/" title="Kubernetes集群可视化监控之-Weave Scope">Kubernetes集群可视化监控之-Weave Scope</a><time datetime="2021-03-25T11:46:36.000Z" title="发表于 2021-03-25 19:46:36">2021-03-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/zaker/2021/03/25/Linux%E5%B0%86%E6%99%AE%E9%80%9A%E7%94%A8%E6%88%B7%E5%8A%A0%E5%85%A5sudo%E7%BB%84/" title="Linux将一般用户加入sudo组"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/zaker/img/404.jpg'" alt="Linux将一般用户加入sudo组"/></a><div class="content"><a class="title" href="/zaker/2021/03/25/Linux%E5%B0%86%E6%99%AE%E9%80%9A%E7%94%A8%E6%88%B7%E5%8A%A0%E5%85%A5sudo%E7%BB%84/" title="Linux将一般用户加入sudo组">Linux将一般用户加入sudo组</a><time datetime="2021-03-25T11:46:36.000Z" title="发表于 2021-03-25 19:46:36">2021-03-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/zaker/2021/03/03/Kubectl%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/" title="kubectl 基本使用"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/zaker/img/404.jpg'" alt="kubectl 基本使用"/></a><div class="content"><a class="title" href="/zaker/2021/03/03/Kubectl%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/" title="kubectl 基本使用">kubectl 基本使用</a><time datetime="2021-03-03T11:46:36.000Z" title="发表于 2021-03-03 19:46:36">2021-03-03</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2021 By 张十三</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/zaker/js/utils.js"></script><script src="/zaker/js/main.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="false"></script><script defer="defer" id="fluttering_ribbon" mobile="true" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-nest.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>